package yxw.com.smartbutler.utils;

import android.content.Context;
import android.content.SharedPreferences;

/*
 *  项目名： SmartButler
 *  包名:    yxw.com.smartbutler.utils
 *  文件名： ShareUtils
 *  创建者：小威.岳
 *  创建时间：2018/11/13 10:26
 *  描述： SharedPreferences封装
 */public class ShareUtils {
    private final static String NAME = "config";

    //键值
    public static void putString(Context mContext, String key, String value) {


        SharedPreferences sharedPreferences = mContext.getSharedPreferences(NAME, Context.MODE_PRIVATE);
        sharedPreferences.edit().putString(key, value).commit();
    }

    //键  默认值
    public static String getString(Context mContext, String key, String value) {


        SharedPreferences sharedPreferences = mContext.getSharedPreferences(NAME, Context.MODE_PRIVATE);
        return sharedPreferences.getString(key, value);
    }

    //键值
    public static void putInt(Context mContext, String key, int value) {


        SharedPreferences sharedPreferences = mContext.getSharedPreferences(NAME, Context.MODE_PRIVATE);
        sharedPreferences.edit().putInt(key, value).commit();
    }

    //键  默认值
    public static int getInt(Context mContext, String key, int value) {


        SharedPreferences sharedPreferences = mContext.getSharedPreferences(NAME, Context.MODE_PRIVATE);
        return sharedPreferences.getInt(key, value);
    }

    //键值
    public static void putBoolean(Context mContext, String key, boolean value) {


        SharedPreferences sharedPreferences = mContext.getSharedPreferences(NAME, Context.MODE_PRIVATE);
        sharedPreferences.edit().putBoolean(key, value).commit();
    }

    //键  默认值
    public static Boolean getBoolean(Context mContext, String key, boolean value) {


        SharedPreferences sharedPreferences = mContext.getSharedPreferences(NAME, Context.MODE_PRIVATE);
        return sharedPreferences.getBoolean(key, value);
    }
//删除单个
    public static void delShare(Context mContext,String key){
        SharedPreferences sharedPreferences = mContext.getSharedPreferences(NAME, Context.MODE_PRIVATE);
        sharedPreferences.edit().remove(key).commit();
    }

    //删除全部
    public static void delShareAll(Context mContext,String key){
        SharedPreferences sharedPreferences = mContext.getSharedPreferences(NAME, Context.MODE_PRIVATE);
        sharedPreferences.edit().clear().commit();
    }
}
